package com.ruoyi.system.mapper;

import com.ruoyi.common.core.dao.BaseMapper;
import com.ruoyi.common.entity.DO.product.ShopProductDO;
import com.ruoyi.common.entity.VO.product.RechargeProductVO;
import com.ruoyi.common.entity.VO.shop.ShopProductSearchVO;
import com.ruoyi.common.entity.VO.shop.ShopProductVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 商品店铺关联 数据层
 */
public interface IBackShopProductMapper extends BaseMapper<ShopProductDO> {

    /**
     * 查询已关联的商品列表
     *
     * @param shopProductSearchVO
     * @return 商品列表
     */
    List<ShopProductVO> searchList(ShopProductSearchVO shopProductSearchVO);

    List<RechargeProductVO> searchRechargeList(ShopProductSearchVO searchVO);

    RechargeProductVO getRechargeProductDetail(ShopProductSearchVO searchVO);

    ShopProductVO getDetailById(Long id);

    int multiInsert(List<ShopProductDO> linkList);

    int multiUpdate(ShopProductVO shopProductVO);

    int multiDelete(Long[] ids);

    @Delete("DELETE FROM shop_product WHERE product_id=#{productId}")
    int deleteByProductId(Long productId);

    @Select("SELECT shop_id FROM shop_product WHERE product_id=#{productId} and is_delete=0")
    List<Long> searchShopListByProductId(Long productId);

    @Update("UPDATE product SET has_attribute=1 WHERE id=#{productId}")
    int updateHasAttribute(Long productId);

    @Update("UPDATE product set stock=stock-1 WHERE id=#{productId}")
    int stockSubtraction (Long productId);

    @Update("UPDATE shop_product set sale=sale+1 WHERE shop_id=#{shopId} and product_id=#{productId}")
    int shopSaleIncrement(@Param("shopId") Long shopId, @Param("productId") Long productId);

    @Update("UPDATE product set sale=sale+1 WHERE id=#{productId}")
    int saleIncrement(Long productId);


}
